package edu.mapi.ir.viewer;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;
import java.awt.image.BufferedImage;

/**
 * @author ZP
 */
public class ChessLayer implements IMapLayer {

	private double width = 10, height = 10, cellWidth = 1;
	private BufferedImage img = null;
	private double lastZoom = 1.0;
	
	public ChessLayer(Maze maze) {
		this.width = maze.getWidth();
		this.height = maze.getHeight();
	}
	
	public BufferedImage getLayerImage(double zoom) {
		if (img == null || zoom != lastZoom) {
			img = new BufferedImage((int)(width*zoom), (int)(height*zoom), BufferedImage.TYPE_INT_ARGB);
			Graphics2D g = (Graphics2D) img.getGraphics();
			g.setColor(new Color(255,255,255,20));
			for (double i = 0; i < width; i+= cellWidth) {				
				g.draw(new Line2D.Double(i*zoom, 0, i*zoom, height*zoom));
			}
			for (double i = height; i >= 0; i-= cellWidth) {				
				g.draw(new Line2D.Double(0, i*zoom, width*zoom, i*zoom));
			}
			//g.setColor(Color.yellow);
			//for (double i = 0; i < width; i+= cellWidth) {				
			//	for (double j = height; j >= 0; j-= cellWidth) {
			//		g.drawString((int)i+","+(int)j, (int)(i*zoom), (int)((height-j)*zoom));
			//	}
			//}
			lastZoom = zoom;
		}
		return img;
	}
	
	public boolean hasLayerChanged() {
		return false;
	}
	
}
